package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.KsAttachment;
import com.ruoyi.system.service.IKsAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客诉工单附件Controller
 *
 * @author hjf
 * @date 2025-07-10
 */
@RestController
@RequestMapping("/hmk/ksAttachment")
public class KsAttachmentController extends BaseController {
    @Autowired
    private IKsAttachmentService ksAttachmentService;

    /**
     * 查询客诉工单附件列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:ksAttachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(KsAttachment ksAttachment) {
        startPage();
        List<KsAttachment> list = ksAttachmentService.selectKsAttachmentList(ksAttachment);
        return getDataTable(list);
    }

    /**
     * 导出客诉工单附件列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:ksAttachment:export')")
    //@Log(title = "客诉工单附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KsAttachment ksAttachment) {
        List<KsAttachment> list = ksAttachmentService.selectKsAttachmentList(ksAttachment);
        ExcelUtil<KsAttachment> util = new ExcelUtil<KsAttachment>(KsAttachment.class);
        util.exportExcel(response, list, "客诉工单附件数据");
    }

    /**
     * 获取客诉工单附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:ksAttachment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ksAttachmentService.selectKsAttachmentById(id));
    }

    /**
     * 新增客诉工单附件
     */
    @PreAuthorize("@ss.hasPermi('hmk:ksAttachment:add')")
    //@Log(title = "客诉工单附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KsAttachment ksAttachment) {
        return toAjax(ksAttachmentService.insertKsAttachment(ksAttachment));
    }

    /**
     * 修改客诉工单附件
     */
    @PreAuthorize("@ss.hasPermi('hmk:ksAttachment:edit')")
    //@Log(title = "客诉工单附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KsAttachment ksAttachment) {
        return toAjax(ksAttachmentService.updateKsAttachment(ksAttachment));
    }

    /**
     * 删除客诉工单附件
     */
    @PreAuthorize("@ss.hasPermi('hmk:ksAttachment:remove')")
    //@Log(title = "客诉工单附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ksAttachmentService.deleteKsAttachmentByIds(ids));
    }
}
